import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/langs/text_key.dart';
import 'package:oramemo/widget/gradient_app_head.dart';
import 'package:oramemo/widget/gradient_background.dart';

import 'index.dart';

class LanguagePage extends GetView<LanguageController> {
  const LanguagePage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LanguageController>(
      init: LanguageController(),
      builder: (_) {
        return Scaffold(
          body: Column(
            children: [
              GradientAppHead(title: TextKey.settingsLanguage.tr),
              Expanded(
                child: GradientBackground(
                    child: [
                  for (var item in controller.languages)
                    Container(
                      color: Colors.white.withAlpha(150),
                      child: ListTile(
                        title: Text(item.title),
                        trailing: GlobalService.to.locale ==
                                Locale(item.languageCode, item.countryCode)
                            ? const Icon(Icons.check)
                            : null,
                        onTap: () {
                          controller.changeLang(item);
                        },
                      ),
                    )
                ].toListView(
                  padding: EdgeInsets.zero,
                  separator: const DividerX(),
                )),
              ),
            ],
          ),
        );
      },
    );
  }
}
